function findContentChildren(g,s) {
  const m = g.length, n = s.length;
  let ans = 0;

  g.sort((a, b) => a - b);
  s.sort((a, b) => a - b);

  for (let i = 0, j = 0; i < m && j < n; j++, i++) {
    while (j < n && g[i] > s[j]) {
      j++;
    }
    if(j < n) {
      ans++;
    }
  }
  return ans;
}

const g = [1,2], s = [1,2,3]
console.log(findContentChildren(g,s))